package ufabc.edu.va.agenteminhoca;

import sim.engine.SimState;
import sim.field.grid.SparseGrid2D;
import sim.util.Interval;

@SuppressWarnings("serial")
public class Minhocas extends SimState {

//    int plantBirth = 1; // in rows, in clumps, at random, along the bottom, along the edges
//    int plantRebirth = 0; // grows back somewhere, grows back nearby, it's gone
//    int eaterBirth = 2; // at center, in a corner, random spot, parent's location
    public int populationSize = 50;
    int plantCount = 250;
	double randomMultiplier = 0.1;
    double mutationProbability = 0.01;
    double crossoverProbability = 0.8;
	private int gridWidth = 150;
	private int gridHeight = 150;
	private int yearDuration = 300;
	private boolean fixedPopulation = true;
	
	public int getPopulationSize() {return populationSize;}
	public void setPopulationSize(int populationSize) {this.populationSize = populationSize;}

	public int getPlantCount() {return plantCount;}
	public void setPlantCount(int plantCount) {this.plantCount = plantCount;}

	
	public double getRandomMultiplier() {return randomMultiplier;}
	public void setRandomMultiplier(double randomMultiplier) {
		if ( randomMultiplier >= 0 && randomMultiplier <= 1)
			this.randomMultiplier = randomMultiplier;}
	public Object domRandomMultiplier() {return new Interval(0.0,1.0);}
	
	
	public double getMutationProbability() {return mutationProbability;}
	public void setMutationProbability(double mutationProbability) {
		if ( mutationProbability >= 0 && mutationProbability <= 1)
			this.mutationProbability = mutationProbability;}
	public Object domMutationProbability() {return new Interval(0.0,0.1);}
	
	public double getCrossoverProbability() {return crossoverProbability;}
	public void setCrossoverProbability(double crossoverProbability) {
		if ( crossoverProbability >= 0 && crossoverProbability <= 1)
			this.crossoverProbability = crossoverProbability;}
	public Object domCrossoverProbability() {return new Interval(0.0,1.0);}
	
	public int getGridWidth() {return gridWidth;}
	public void setGridWidth(int gridWidth) {this.gridWidth = gridWidth;}

	public int getGridHeight() {return gridHeight;}
	public void setGridHeight(int gridHeight) {this.gridHeight = gridHeight;}

	public int getYearDuration() {
		return yearDuration;
	}
	public void setYearDuration(int yearDuration) {
		this.yearDuration = yearDuration;
	}
	public boolean isFixedPopulation() {
		return fixedPopulation;
	}
	public void setFixedPopulation(boolean fixedPopulation) {
		this.fixedPopulation = fixedPopulation;
	}

	public SparseGrid2D worldMinhocas;
	public SparseGrid2D worldComidas;
	
	private Mundo mundo;
	private InfoUI info;
	
	public void setInfoMundo(InfoUI iui) {
		this.info = iui;
	}
	
	public InfoUI getInfo() {
		return info;
	}
	public Minhocas(long seed) {
		super(seed);
		worldMinhocas = new SparseGrid2D(gridWidth, gridHeight);
		worldComidas = new SparseGrid2D(gridWidth, gridHeight);
	}
	
	public void start()
	{
		super.start();
		// clear the world
		mundo = new Mundo(this);
		
		schedule.scheduleRepeating(mundo);

	}
		
	public static void main(String[] args)
	{
		doLoop(Minhocas.class, args);
		System.exit(0);
	}
}
